﻿using System;
using System.Numerics;

class TrailingZeros
{
    static void Main()
    {
        //Exercise 13.*
        //* Write a program that calculates for given N how many trailing zeros present at the end of the number N!. 
        //Examples:	N = 10 -> N! = 3628800 -> 2
        //N = 20 -> N! = 2432902008176640000 -> 4
        //Does your program work for N = 50 000? - 12496
        //Hint: The trailing zeros in N! are equal to the number of its prime divisors of value 5. Think why!

        Console.Write("Enter N:  ");
        int number = int.Parse(Console.ReadLine());
        BigInteger factorielN = 1;        
        int result = 0;
        int numberForFormula = number;        
        int divider = 5;
        
        for (int i = 1; i <= number; i++)
        {
            factorielN *= i;            
        }
        Console.WriteLine("N! =  {0}",factorielN);

        for (int j = 1; j <= number; j++)
        {
            result = result + (numberForFormula / divider);
            divider = divider * 5;            
        }
        Console.WriteLine("The trailing zeros are:  {0}",result);        
    }
}

